<?php 

	include('cms.php'); 
	
	Cms::nocache(); 
	
	if( !isset($_GET['idcontent']) ){
		die($strings['geterror']);
	}
	
	if(isset($_GET['p'])){
		$page = $_GET['p'] + 0;
	}else{
		$page = 1;
	}
	
	if(!$page) $page = 1;
	
	$pagesize = 10;
	$idcontent = $_GET['idcontent'];
	$total = Comment::bycontentid_count($idcontent);
	$comments = Comment::bycontentid($idcontent, $page, $pagesize);
	$pages = ceil($total / $pagesize);


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Comments</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>

<style type="text/css">
	
	body{ width:auto; height:auto; font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif; }
	
	.content-comment-page{
		text-decoration:none;
		color:#444;
		display:inline-block;
		padding:.25em .8em;
		margin:.5em;
		background:#f6f6f6;
		border:solid 1px #CCC;
		border-left-color:#fcfcfc;
		border-top-color:#fcfcfc;
	}
	
	.content-comment-page:hover{
		color:red;
	}
	
	.content-comment-current-page{
		background:none !important;
		border-color:transparent !important;
	}
	
	.content-comment-previous, .content-comment-next{
		text-decoration:none;
		display:inline-block;
		margin:0.5em;
	}
	
	.content-comment-previous:hover, .content-comment-next:hover{
		color:#09F;
	}
	
	.cms-comment-form label{
		margin-top:1em;
		display:block;
	}
	
	.cms-comment-form input, .cms-comment-form textarea{
		display:block;
		padding:.5em;
	}
	
	.cms-comment-form input[type="submit"]{
		margin-top:2em;
	}
	
	.cms-comment-form small{
		font-size:8pt;
		margin-left:1em;
		color:#999;
	}
	
	.cms-comment-form em{
		font-style:normal;
		font-size:8pt;
		margin-left:1em;
		color:#F66;
	}
	
	.content-comment{
		margin:2em 0 0 0;
		clear:both;
	}
	
	.content-comment-metadata{
		font-size:.8em;
		float:left;
		width:20%;
		text-align:left;
		
	}
	
	.content-comment-body{
		float:left;
		width:80%;
	}
	
	.content-comment-placer-title{ 
		clear:both;
		margin-top:2em;
	}
	
	.content-comment-title{
		font-weight:bold;
		border-bottom:solid 1px #ccc;
	}
	
	.content-comment-pages{
		clear:both;
	}
</style>
<?php
	
	if(CmsConfig::$comments_css){
		echo '<link rel="stylesheet" type="text/css" href="' . CmsConfig::$comments_css . '"/>';
	}
	
?>
</head>

<body>
<h1 class="content-comments-title"><?=$strings['comments']?></h1>
<?php
	
	foreach($comments as $comment){
		
		echo '<div class="content-comment">' .
				'<div class="content-comment-metadata">' . 
					'<div class="content-comment-name">' . ($comment->name ? $comment->name : '(' . $strings['anonymous'] . ')') . '</div>' .
					'<div class="content-comment-created">' . $comment->created . '</div>' .
				'</div>' .
				'<div class="content-comment-body">' .
					'<div class="content-comment-title">' . $comment->title . '</div>' .
					'<div class="content-comment-text">' . $comment->text . '</div>' .
				'</div><div style="clear:both"></div>'.
			'</div>';
		
	}
	
	if($pages > 1){
		
		echo '<div clas="content-comment-pages">';
		
		if($page > 1){
			echo '<a class="content-comment-previous" href="comments.php?idcontent=' . $idcontent . '&p=' . ($page - 1) . '"> &laquo; ' . $strings['previous'] . '</a>';
		}
		
		for($i = 1; $i <= $pages; $i++){
			echo '<a href="comments.php?idcontent=' . $idcontent . '&p=' . $i . '" class="content-comment-page ' . ($page == $i ? 'content-comment-current-page' : '') . '">' . $i . '</a>';
		}
		
		if($page < $pages){
			echo '<a class="content-comment-next" href="comments.php?idcontent=' . $idcontent . '&p=' . ($page + 1) . '">' . $strings['next'] . ' &raquo; </a>';
		}
		
		echo "</div>";
	}
	
?>
<div style="clear:both"></div>
<h2 class="content-comment-placer-title"><?=$strings['addcomment']?></h2>
<form class="cms-comment-form" method="post" action="comments-post.php">
	 <input type="hidden" name="idcontent" value="<?=$idcontent?>" />
	 <label class="cms-comment-namelabel"><?=$strings['yourname']?><small><?=$strings['optional']?></small></label>
     <input class="cms-comment-name" type="text" name="name" size="50" />
     <label class="cms-comment-emaillabel"><?=$strings['youremail']?><small><?=$strings['optional']?></small></label>
     <input class="cms-comment-email" type="text" name="email" size="50" />
     <label class="cms-comment-titlelabel"><?=$strings['title']?><small><?=$strings['optional']?></small></label>
     <input class="cms-comment-title" type="text" name="title" size="50" />
     <label class="cms-comment-textlabel"><?=$strings['comment']?><em><?=$strings['required']?></em></label>
     <textarea class="cms-comment-text" name="text" rows="6" cols="50"></textarea>
     <?php if(!Session::logged()){ ?>
     	<label class="cms-comment-captchalabel"><?=$strings['writethis']?>: <img src="captcha.php" align="absmiddle" alt="<?=$strings['captchaexplain']?>" title="<?=$strings['captchaexplain']?>" /><em><?=$strings['required']?></em></label>
        <input class="cms-comment-captcha" type="text" name="captcha"  />
     <? } ?>
     <label></label>
     <input  class="cms-comment-submit" type="submit" value="<?=$strings['postcomment']?>" />
     
</form>
</body>
</html>